package cn.caplike.demo.repository.java;

/**
 * Description: 0x
 *
 * @author LiKe
 * @version 1.0.0
 * @date 2020-09-13 16:00
 */
public class AboutByte {

    public static void main(String[] args) {
        // a();
        byteMinus();
    }

    private static void a() {
        // ~ byte
        //   字节 (byte) 数据类型是 8 位有符号Java原始整数数据类型。其范围是 -128 至 127 (-2^7 至 2^7-1)。字节类型是Java中可用的最小整数数据类型。
        //   为什么在java中（byte）128输出是-128? -> https://juejin.im/post/6844903776063602702
        //   byte的取值范围为什么是-128~127？ -> https://www.jianshu.com/p/47761557bab0
        final byte x = (byte) 128;
        final int i = x;
        System.out.println(x);
        System.out.println(i);

        final int j = 1000;
        final byte y = (byte) j;

        byte a = (byte) 0x80;
        byte b = (byte) 0xFFFFFFFF;
        byte c = (byte) 0x0100;
        System.out.println(a);
        System.out.println(b);
        System.out.println(c);

        System.out.println(Integer.toBinaryString(0x80));
        System.out.println("0x1: " + 0x10);

        System.out.println(0xFF & 123);
    }

    public static void byteMinus() {
        byte a = 127;
        byte b = (byte) (a - 1);
        System.out.println(b);
    }

}
